<!DOCTYPE HTML>
<?php 
header("Access-Control-Allow-Origin:*");  //I have also tried the * wildcard and get the same response
require_once('Easemob.class.php');
$ar = array("client_id"=>"YXA6R8DP4D1zEeWxlJPcNSkVvg","client_secret"=>"YXA6uvZ6cKetm1jcnPKoPJSxhqW2n-0","org_name"=>"zdl411437734","app_name"=>"hxltkfdemo");
$mes = new Easemob($ar);
if($_SERVER['REQUEST_METHOD']=="POST"){
	//echo "PSOT 请求<br/>";
	 //var_dump($_POST);
	 $type=$_POST["mytype"];
	 if($type==1){//注册
	 	echo "注册请求<br/>";
		 if(isset($_POST["username"])&&strlen($_POST["username"])>0&&isset($_POST["password"])&&strlen($_POST["password"])>0){
		 	 $options=array("username"=>$_POST["username"],"password"=>$_POST["password"]);
			echo $mes->openRegister($options);
		 }else{
		 	echo "用户名或者密码有一项没有填写，请求填写<br/>";
		 }
	 }else if($type==2){//授权注册模式 || 批量注册
		echo "授权注册模式 || 批量注册   请求<br/>";
		if(isset($_POST["username"])&&strlen($_POST["username"])>0&&isset($_POST["password"])&&strlen($_POST["password"])>0){
		$options=array(array("username"=>$_POST["username"],"password"=>$_POST["password"]),array("username"=>$_POST["username1"],"password"=>$_POST["password1"]));
		echo $mes->accreditRegister($options);
		}else{
			echo "用户名或者密码有一项没有填写，请求填写<br/>";
		}
	 }else if($type==3){//获取指定用户详情
		echo "获取指定用户详情 请求<br/>";
		if(isset($_POST["username"])&&strlen($_POST["username"])>0){
			echo $mes->userDetails($_POST["username"]);
		}else{
			echo "用户名没有填写，请求填写<br/>";
		}
	 }else if($type==4){//查看用户是否在线
		echo "查看用户是否在线请求<br/>";
		echo $mes->isOnline($_POST["username"]);	 	
	 }else if($type==5){//发送消息
		echo "发送消息请求<br/>";
		//var_dump($_POST);
		$from_user=$_POST["from_user"];
		if(isset($_POST["username"])&&strlen($_POST["username"])>0){
			$username=array($_POST["username"]);
		}else{
			$username=null;
		}
		$content=$_POST["content"];
		$target_type=$_POST["target_type"];//描述：给一个或者多个用户(users)或者群组发送消息(chatgroups)
		if(isset($_POST["ext"])&&strlen($_POST["ext"])>0){
			$ext=json_decode($_POST["ext"]);
		}else{
			$ext=null;
		}
		//var_dump($ext);
		if(isset($from_user)&&strlen($from_user)>0&&isset($username)&&isset($target_type)&&strlen($target_type)>0){
			echo $mes->yy_hxSend($from_user, $username, $content, $target_type, $ext);
		}else{
			echo "发送者、接受者和发送的类型不能为空";
		}
	 }
	 
}else if($_SERVER['REQUEST_METHOD']=="GET"){
	echo "GET 请求，不支持";
}
?>